
<{include file="app/header.tpl"}>

<form action="" method="POST" class="register" onsubmit="return enter_submit_reg();">

    <input type="button" name="" class="send-code" onclick="return send_code(this);"  value="发送验证码" id="">
    <input type="number" name="mobile" id="" class="number" placeholder="请输入你的手机号" required>
    <input type="number" name="code" id="" class="code" placeholder="请输入您收到的验证码" required>
    <input type="password" class="password" name="password" id="" placeholder="请设置你的登陆密码" required >
    <input type="password" class="again-psd" name="password2" id="" placeholder="请重新输入登录密码" required>
    <p class="error"></p>
    <input type="submit" value="注册" class="submit" onclick="return submit_reg();" >

</form>

<script>

function submit_reg(){
    var mobileNumberReg = /^(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/,
        oNumVal = $('.number').val();
    if (!mobileNumberReg.test(oNumVal)) {
         $('.error').html('请输入正确的手机号码');
         return false;
    }
    var oSend = $('.code').val();
    if (!oSend) {
         $('.error').html('请输入验证码');
         return false;
    }

    // 当验证码错误的时候触发 start
    // $('.error').html('验证码错误')
    // 当验证码错误的时候触发 end

    var oPassword = $('.password').val();
    if (!oPassword) {
        $('.error').html('请输入密码');
        return false;
    }
    var oPassword2 = $('.again-psd').val();
    if (!oPassword2) {
        $('.error').html('请再次输入密码');
        return false;
    }
    if (oPassword !== oPassword2) {
        $('.error').html('两次输入密码不一致');
        return false;
    }
    if (oPassword.length < 6) {
        $('.error').html('密码不能少于6位');
        return false;
    }
}

function enter_submit_reg(){
    submit_reg();
}

function send_code(current) {

    var mobileNumberReg = /^(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/,
        oNumVal = $('.number').val();
    if (!mobileNumberReg.test(oNumVal)) {
         $('.error').html('请输入正确的手机号码');
         return false;
    }

    $('.error').html('');
    $.post('/register/mobileSendCode', { mobile : oNumVal }, function (o) {
            if(o.status == 1)
            {
                $('.error').html('手机号已经注册过，请直接登陆！');
                clearInterval(timer);
                $(current).val('发送验证码');
                $(current).attr('disabled', false);
                i = 60;
                return false;
            }
        }, 'json');

    var i = 60;
    var timer = null;
    timer = setInterval(function() {
        i--;

        if (i < 10) {
            i = '0' + i;
        }

        $(current).val('剩余' + i + '秒');
        $(current).attr('disabled', true);

        if (i <= 0) {
            clearInterval(timer);
            $(current).val('发送验证码');
            $(current).attr('disabled', false);
            i = 60;
        }
    }, 1000);

    return false;
}

document.body.backgroundColor = '#fff';

var register_status = <{$register_status}>;
if(register_status == 1)
{
    $('.error').html('手机认证码错误！');
}

</script>

<{include file="app/footer.tpl"}>
